﻿//#include "y2y.h"
#include "Y2Y.h"


//int main()
void test_y2y()
{
    printf("Hello, world!\n");

    //char str1[] = "Hello, world!";
    //char str2[] = "abcdefghijkln";
    //char temp1[14];
    //char temp2[14];
    //int i;
    //for (i = 0; i < strlen(str1); ++i) {
    //    temp1[i] = str1[i] ^ str2[i];
    //}
    //temp1[i] = 0;
    //printf("str1: %s\n", str1);
    //printf("str2: %s\n", str2);
    //printf("temp: %s\n", temp1);
    //for (i = 0; i < strlen(str1); ++i) {
    //    temp2[i] = temp1[i] ^ str2[i];
    //}
    //temp2[i] = 0;
    //printf("temp2: %s\n", temp2);

    //char m1 = 0b11111111 >> 1;
    //unsigned char mt1 = ~0;
    //char m2 = (char)(mt1 >> 1);
    //char m3 = (unsigned char)(-1) >> 1;
    //char m4 = (char)((unsigned char)(~0) >> 1);
    //printf("m1: %d\n", m1); // 127 ok
    //printf("mt1: %d\n", mt1); // 255
    //printf("m2: %d\n", m2); // 127
    //printf("m3: %d\n", m3); // 127
    //printf("m4: %d\n", m4); // 127
    //printf("sizeof m1: %zu\n", sizeof(m1));

    //char num1    = 0b10111111;
    //char num1_re = 0b10111110;
    //char num2 = 0b1000000;
    //char num3 = 0b0001000;
    //char num4 = 0b1111000;
    //printf("num1: %d\n", num1);
    //printf("num1_re: %d\n", num1_re);
    //printf("num2: %d\n", num2);
    //printf("num1 + num2: %d\n", num2 + num1);
    //printf("num1 & num2: %d\n", num1 & num2);
    //printf("num3: %d\n", num3);
    //printf("num4: %d\n", num4);

    const char* xor_key = "youyu is a lolicon forever and always is a fool";

    y2yCtx ctx;
    init_y2yCtx(&ctx);
    //y2_set_key_content(&ctx, xor_key, 0);
    //y2_set_key_content(&ctx, "前天我遇到了小兔，昨天遇到了小鹿，今天遇到了你，你的名字是一之濑•琴美", 0);
    y2_load_file_key(&ctx, "test_key.txt", 0);
    // 文件加密到文件
    y2_codec_file_to_file(&ctx, "加密文件.txt", "w", "Y2Y.c", 0, 0);
    // 文件解密到文件
    y2_codec_file_to_file(&ctx, "解密文件.txt", "w", "加密文件.txt", 0, 0);
    // 文件解密到内存
    char mem_test[1024];
    y2_codec_file_to_mem(&ctx, mem_test, 1024, "加密文件.txt", 0);
    int xor_len = sizeof(mem_test);
    printf("mem_test: \n%s\n", mem_test);
    // 内存加密到内存
    char mem_test_xor[1024];
    xor_mem(mem_test_xor, mem_test, xor_len, xor_key, strlen(xor_key));
    printf("mem_test_xor: \n");
    for (int i = 0; i < xor_len; ++i)
        printf("%c ", mem_test_xor[i]);
    printf("\n");
    //printf("mem_test_xor: \n%s\n", mem_test_xor);
    // 内存解密到内存
    char mem_test_re[1024];
    y2_set_key_content(&ctx, xor_key, 0);
    y2_xor_mem(&ctx, mem_test_re, mem_test_xor, xor_len);
    printf("mem_test_re: \n");
    for (int i = 0; i < xor_len; ++i)
        printf("%c ", mem_test_re[i]);
    printf("\n");
    // 内存解密到文件
    y2_codec_mem_to_file(&ctx, "内存解密文件.txt", "w", 0, mem_test_xor, xor_len);
    free_y2yCtx(&ctx);

    //return 0;
}

